]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - fs/ksmbd/oplock.h
btrfs: zoned: fix missing endianness conversion in sb_write_pointer
[mirror_ubuntu-jammy-kernel.git] / fs / ksmbd / 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
31#define SMB2_LEASE_KEY_SIZE 16
32
33struct lease_ctx_info {
ade62d8b
NJ
34 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
35 __le32 req_state;
36 __le32 flags;
37 __le64 duration;
38 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
39 int version;
e2f34481
NJ
40};
41
42struct lease_table {
43 char client_guid[SMB2_CLIENT_GUID_SIZE];
44 struct list_head lease_list;
45 struct list_head l_entry;
46 spinlock_t lb_lock;
47};
48
49struct lease {
50 __u8 lease_key[SMB2_LEASE_KEY_SIZE];
51 __le32 state;
52 __le32 new_state;
53 __le32 flags;
54 __le64 duration;
ade62d8b
NJ
55 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE];
56 int version;
57 unsigned short epoch;
e2f34481
NJ
58 struct lease_table *l_lb;
59};
60
61struct oplock_info {
62 struct ksmbd_conn *conn;
63 struct ksmbd_session *sess;
64 struct ksmbd_work *work;
65 struct ksmbd_file *o_fp;
66 int level;
67 int op_state;
68 unsigned long pending_break;
64b39f4a 69 u64 fid;
e2f34481
NJ
70 atomic_t breaking_cnt;
71 atomic_t refcount;
72 __u16 Tid;
73 bool is_lease;
74 bool open_trunc; /* truncate on open */
75 struct lease *o_lease;
76 struct list_head interim_list;
77 struct list_head op_entry;
78 struct list_head lease_entry;
79 wait_queue_head_t oplock_q; /* Other server threads */
80 wait_queue_head_t oplock_brk; /* oplock breaking wait */
81 struct rcu_head rcu_head;
82};
83
84struct lease_break_info {
85 __le32 curr_state;
86 __le32 new_state;
ade62d8b 87 __le16 epoch;
e2f34481
NJ
88 char lease_key[SMB2_LEASE_KEY_SIZE];
89};
90
91struct oplock_break_info {
92 int level;
93 int open_trunc;
94 int fid;
95};
96
64b39f4a 97int smb_grant_oplock(struct ksmbd_work *work, int req_op_level,
070fb21e
NJ
98 u64 pid, struct ksmbd_file *fp, __u16 tid,
99 struct lease_ctx_info *lctx, int share_ret);
64b39f4a 100void smb_break_all_levII_oplock(struct ksmbd_work *work,
070fb21e 101 struct ksmbd_file *fp, int is_trunc);
e2f34481
NJ
102int opinfo_write_to_read(struct oplock_info *opinfo);
103int opinfo_read_handle_to_read(struct oplock_info *opinfo);
104int opinfo_write_to_none(struct oplock_info *opinfo);
105int opinfo_read_to_none(struct oplock_info *opinfo);
106void close_id_del_oplock(struct ksmbd_file *fp);
107void smb_break_all_oplock(struct ksmbd_work *work, struct ksmbd_file *fp);
108struct oplock_info *opinfo_get(struct ksmbd_file *fp);
109void opinfo_put(struct oplock_info *opinfo);
110
111/* Lease related functions */
112void create_lease_buf(u8 *rbuf, struct lease *lease);
113struct lease_ctx_info *parse_lease_state(void *open_req);
114__u8 smb2_map_lease_to_oplock(__le32 lease_state);
115int lease_read_to_write(struct oplock_info *opinfo);
116
117/* Durable related functions */
118void create_durable_rsp_buf(char *cc);
119void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp);
120void create_mxac_rsp_buf(char *cc, int maximal_access);
121void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id);
122void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp);
123struct create_context *smb2_find_context_vals(void *open_req, const char *str);
e2f34481 124struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
070fb21e 125 char *lease_key);
e2f34481 126int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,
070fb21e 127 struct lease_ctx_info *lctx);
e2f34481
NJ
128void destroy_lease_table(struct ksmbd_conn *conn);
129int smb2_check_durable_oplock(struct ksmbd_file *fp,
070fb21e 130 struct lease_ctx_info *lctx, char *name);
e2f34481 131#endif /* __KSMBD_OPLOCK_H */