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 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 ksmbd_conn *conn; 38 struct list_head lease_list; 39 struct list_head l_entry; 40 spinlock_t lb_lock; 41 }; 42 43 struct lease { 44 __u8 lease_key[SMB2_LEASE_KEY_SIZE]; 45 __le32 state; 46 __le32 new_state; 47 __le32 flags; 48 __le64 duration; 49 __u8 parent_lease_key[SMB2_LEASE_KEY_SIZE]; 50 int version; 51 unsigned short epoch; 52 bool is_dir; 53 bool reuse_epoch; 54 struct ksmbd_inode *ci; 55 struct lease_table *l_lb; 56 struct list_head l_entry; 57 struct list_head open_list; 58 spinlock_t lock; 59 atomic_t refcount; 60 }; 61 62 struct oplock_info { 63 struct ksmbd_conn *conn; 64 struct ksmbd_session *sess; 65 struct ksmbd_work *work; 66 struct ksmbd_file *o_fp; 67 int level; 68 int op_state; 69 spinlock_t state_lock; 70 unsigned long pending_break; 71 u64 fid; 72 atomic_t breaking_cnt; 73 atomic_t refcount; 74 __u16 Tid; 75 bool is_lease; 76 bool open_trunc; /* truncate on open */ 77 struct lease *o_lease; 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; 83 }; 84 85 struct lease_break_info { 86 __le32 curr_state; 87 __le32 new_state; 88 __le16 epoch; 89 char lease_key[SMB2_LEASE_KEY_SIZE]; 90 }; 91 92 struct oplock_break_info { 93 int level; 94 int open_trunc; 95 int fid; 96 }; 97 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, bool replay); 101 void smb_break_all_levII_oplock(struct ksmbd_work *work, 102 struct ksmbd_file *fp, int is_trunc); 103 void smb_break_all_levII_oplock_rename(struct ksmbd_work *work, struct ksmbd_file *fp); 104 void smb_break_all_levII_oplock_no_interim(struct ksmbd_work *work, 105 struct ksmbd_file *fp, int is_trunc); 106 void smb_break_all_levII_oplock_for_delete(struct ksmbd_work *work, 107 struct ksmbd_file *fp); 108 int opinfo_write_to_read(struct oplock_info *opinfo); 109 int opinfo_read_handle_to_read(struct oplock_info *opinfo); 110 int opinfo_write_to_none(struct oplock_info *opinfo); 111 int opinfo_read_to_none(struct oplock_info *opinfo); 112 void close_id_del_oplock(struct ksmbd_file *fp); 113 void smb_break_all_oplock(struct ksmbd_work *work, struct ksmbd_file *fp); 114 struct oplock_info *opinfo_get(struct ksmbd_file *fp); 115 void opinfo_put(struct oplock_info *opinfo); 116 117 /* Lease related functions */ 118 void create_lease_buf(u8 *rbuf, struct lease *lease); 119 struct lease_ctx_info *parse_lease_state(void *open_req); 120 __u8 smb2_map_lease_to_oplock(__le32 lease_state); 121 void lease_update_oplock_levels(struct lease *lease); 122 int lease_read_to_write(struct oplock_info *opinfo); 123 124 /* Durable related functions */ 125 void create_durable_rsp_buf(char *cc); 126 void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp); 127 void create_mxac_rsp_buf(char *cc, int maximal_access); 128 void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id); 129 void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp); 130 void create_aapl_rsp_buf(char *cc, __u64 vol_caps, __u64 req_bitmap, 131 bool readdir_attr_v2); 132 struct create_context *smb2_find_context_vals(void *open_req, const char *tag, int tag_len); 133 struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn, 134 char *lease_key); 135 int find_same_lease_key(struct ksmbd_conn *conn, struct ksmbd_inode *ci, 136 struct lease_ctx_info *lctx); 137 void destroy_lease_table(struct ksmbd_conn *conn); 138 void smb_send_parent_lease_break_noti(struct ksmbd_file *fp, 139 struct lease_ctx_info *lctx); 140 void smb_lazy_parent_lease_break_close(struct ksmbd_file *fp); 141 int smb2_check_durable_oplock(struct ksmbd_conn *conn, 142 struct ksmbd_share_config *share, 143 struct ksmbd_file *fp, 144 struct lease_ctx_info *lctx, 145 struct ksmbd_user *user, 146 char *name); 147 #endif /* __KSMBD_OPLOCK_H */ 148