Lines Matching refs:opinfo

35 	struct oplock_info *opinfo;  in alloc_opinfo()  local
37 opinfo = kzalloc(sizeof(struct oplock_info), GFP_KERNEL); in alloc_opinfo()
38 if (!opinfo) in alloc_opinfo()
41 opinfo->sess = sess; in alloc_opinfo()
42 opinfo->conn = conn; in alloc_opinfo()
43 opinfo->level = SMB2_OPLOCK_LEVEL_NONE; in alloc_opinfo()
44 opinfo->op_state = OPLOCK_STATE_NONE; in alloc_opinfo()
45 opinfo->pending_break = 0; in alloc_opinfo()
46 opinfo->fid = id; in alloc_opinfo()
47 opinfo->Tid = Tid; in alloc_opinfo()
48 INIT_LIST_HEAD(&opinfo->op_entry); in alloc_opinfo()
49 INIT_LIST_HEAD(&opinfo->interim_list); in alloc_opinfo()
50 init_waitqueue_head(&opinfo->oplock_q); in alloc_opinfo()
51 init_waitqueue_head(&opinfo->oplock_brk); in alloc_opinfo()
52 atomic_set(&opinfo->refcount, 1); in alloc_opinfo()
53 atomic_set(&opinfo->breaking_cnt, 0); in alloc_opinfo()
54 atomic_inc(&opinfo->conn->refcnt); in alloc_opinfo()
56 return opinfo; in alloc_opinfo()
59 static void lease_add_list(struct oplock_info *opinfo) in lease_add_list() argument
61 struct lease_table *lb = opinfo->o_lease->l_lb; in lease_add_list()
64 list_add_rcu(&opinfo->lease_entry, &lb->lease_list); in lease_add_list()
68 static void lease_del_list(struct oplock_info *opinfo) in lease_del_list() argument
70 struct lease_table *lb = opinfo->o_lease->l_lb; in lease_del_list()
76 if (list_empty(&opinfo->lease_entry)) { in lease_del_list()
81 list_del_init(&opinfo->lease_entry); in lease_del_list()
82 opinfo->o_lease->l_lb = NULL; in lease_del_list()
93 static int alloc_lease(struct oplock_info *opinfo, struct lease_ctx_info *lctx) in alloc_lease() argument
110 INIT_LIST_HEAD(&opinfo->lease_entry); in alloc_lease()
111 opinfo->o_lease = lease; in alloc_lease()
116 static void free_lease(struct oplock_info *opinfo) in free_lease() argument
120 lease = opinfo->o_lease; in free_lease()
124 static void free_opinfo(struct oplock_info *opinfo) in free_opinfo() argument
126 if (opinfo->is_lease) in free_opinfo()
127 free_lease(opinfo); in free_opinfo()
128 if (opinfo->conn && atomic_dec_and_test(&opinfo->conn->refcnt)) in free_opinfo()
129 kfree(opinfo->conn); in free_opinfo()
130 kfree(opinfo); in free_opinfo()
135 struct oplock_info *opinfo; in opinfo_free_rcu() local
137 opinfo = container_of(rcu_head, struct oplock_info, rcu_head); in opinfo_free_rcu()
138 free_opinfo(opinfo); in opinfo_free_rcu()
143 struct oplock_info *opinfo; in opinfo_get() local
146 opinfo = rcu_dereference(fp->f_opinfo); in opinfo_get()
147 if (opinfo && !atomic_inc_not_zero(&opinfo->refcount)) in opinfo_get()
148 opinfo = NULL; in opinfo_get()
151 return opinfo; in opinfo_get()
156 struct oplock_info *opinfo; in opinfo_get_list() local
162 opinfo = list_first_or_null_rcu(&ci->m_op_list, struct oplock_info, in opinfo_get_list()
164 if (opinfo) { in opinfo_get_list()
165 if (opinfo->conn == NULL || in opinfo_get_list()
166 !atomic_inc_not_zero(&opinfo->refcount)) in opinfo_get_list()
167 opinfo = NULL; in opinfo_get_list()
169 if (ksmbd_conn_releasing(opinfo->conn)) { in opinfo_get_list()
170 atomic_dec(&opinfo->refcount); in opinfo_get_list()
171 opinfo = NULL; in opinfo_get_list()
178 return opinfo; in opinfo_get_list()
181 void opinfo_put(struct oplock_info *opinfo) in opinfo_put() argument
183 if (!opinfo) in opinfo_put()
186 if (!atomic_dec_and_test(&opinfo->refcount)) in opinfo_put()
189 call_rcu(&opinfo->rcu_head, opinfo_free_rcu); in opinfo_put()
192 static void opinfo_add(struct oplock_info *opinfo) in opinfo_add() argument
194 struct ksmbd_inode *ci = opinfo->o_fp->f_ci; in opinfo_add()
197 list_add_rcu(&opinfo->op_entry, &ci->m_op_list); in opinfo_add()
201 static void opinfo_del(struct oplock_info *opinfo) in opinfo_del() argument
203 struct ksmbd_inode *ci = opinfo->o_fp->f_ci; in opinfo_del()
205 if (opinfo->is_lease) { in opinfo_del()
207 lease_del_list(opinfo); in opinfo_del()
211 list_del_rcu(&opinfo->op_entry); in opinfo_del()
245 int opinfo_write_to_read(struct oplock_info *opinfo) in opinfo_write_to_read() argument
247 struct lease *lease = opinfo->o_lease; in opinfo_write_to_read()
249 if (!(opinfo->level == SMB2_OPLOCK_LEVEL_BATCH || in opinfo_write_to_read()
250 opinfo->level == SMB2_OPLOCK_LEVEL_EXCLUSIVE)) { in opinfo_write_to_read()
251 pr_err("bad oplock(0x%x)\n", opinfo->level); in opinfo_write_to_read()
252 if (opinfo->is_lease) in opinfo_write_to_read()
256 opinfo->level = SMB2_OPLOCK_LEVEL_II; in opinfo_write_to_read()
258 if (opinfo->is_lease) in opinfo_write_to_read()
269 int opinfo_read_handle_to_read(struct oplock_info *opinfo) in opinfo_read_handle_to_read() argument
271 struct lease *lease = opinfo->o_lease; in opinfo_read_handle_to_read()
274 opinfo->level = SMB2_OPLOCK_LEVEL_II; in opinfo_read_handle_to_read()
284 int opinfo_write_to_none(struct oplock_info *opinfo) in opinfo_write_to_none() argument
286 struct lease *lease = opinfo->o_lease; in opinfo_write_to_none()
288 if (!(opinfo->level == SMB2_OPLOCK_LEVEL_BATCH || in opinfo_write_to_none()
289 opinfo->level == SMB2_OPLOCK_LEVEL_EXCLUSIVE)) { in opinfo_write_to_none()
290 pr_err("bad oplock(0x%x)\n", opinfo->level); in opinfo_write_to_none()
291 if (opinfo->is_lease) in opinfo_write_to_none()
295 opinfo->level = SMB2_OPLOCK_LEVEL_NONE; in opinfo_write_to_none()
296 if (opinfo->is_lease) in opinfo_write_to_none()
307 int opinfo_read_to_none(struct oplock_info *opinfo) in opinfo_read_to_none() argument
309 struct lease *lease = opinfo->o_lease; in opinfo_read_to_none()
311 if (opinfo->level != SMB2_OPLOCK_LEVEL_II) { in opinfo_read_to_none()
312 pr_err("bad oplock(0x%x)\n", opinfo->level); in opinfo_read_to_none()
313 if (opinfo->is_lease) in opinfo_read_to_none()
317 opinfo->level = SMB2_OPLOCK_LEVEL_NONE; in opinfo_read_to_none()
318 if (opinfo->is_lease) in opinfo_read_to_none()
329 int lease_read_to_write(struct oplock_info *opinfo) in lease_read_to_write() argument
331 struct lease *lease = opinfo->o_lease; in lease_read_to_write()
341 opinfo->level = SMB2_OPLOCK_LEVEL_BATCH; in lease_read_to_write()
343 opinfo->level = SMB2_OPLOCK_LEVEL_EXCLUSIVE; in lease_read_to_write()
354 static int lease_none_upgrade(struct oplock_info *opinfo, __le32 new_state) in lease_none_upgrade() argument
356 struct lease *lease = opinfo->o_lease; in lease_none_upgrade()
367 opinfo->level = SMB2_OPLOCK_LEVEL_BATCH; in lease_none_upgrade()
369 opinfo->level = SMB2_OPLOCK_LEVEL_II; in lease_none_upgrade()
371 opinfo->level = SMB2_OPLOCK_LEVEL_EXCLUSIVE; in lease_none_upgrade()
373 opinfo->level = SMB2_OPLOCK_LEVEL_II; in lease_none_upgrade()
384 struct oplock_info *opinfo; in close_id_del_oplock() local
389 opinfo = opinfo_get(fp); in close_id_del_oplock()
390 if (!opinfo) in close_id_del_oplock()
393 opinfo_del(opinfo); in close_id_del_oplock()
396 if (opinfo->op_state == OPLOCK_ACK_WAIT) { in close_id_del_oplock()
397 opinfo->op_state = OPLOCK_CLOSING; in close_id_del_oplock()
398 wake_up_interruptible_all(&opinfo->oplock_q); in close_id_del_oplock()
399 if (opinfo->is_lease) { in close_id_del_oplock()
400 atomic_set(&opinfo->breaking_cnt, 0); in close_id_del_oplock()
401 wake_up_interruptible_all(&opinfo->oplock_brk); in close_id_del_oplock()
406 atomic_dec(&opinfo->refcount); in close_id_del_oplock()
407 opinfo_put(opinfo); in close_id_del_oplock()
476 static inline int compare_guid_key(struct oplock_info *opinfo, in compare_guid_key() argument
481 guid2 = opinfo->conn->ClientGUID; in compare_guid_key()
482 key2 = opinfo->o_lease->lease_key; in compare_guid_key()
505 struct oplock_info *opinfo; in same_client_has_lease() local
516 list_for_each_entry(opinfo, &ci->m_op_list, op_entry) { in same_client_has_lease()
517 if (!opinfo->is_lease || !opinfo->conn) in same_client_has_lease()
519 lease = opinfo->o_lease; in same_client_has_lease()
521 ret = compare_guid_key(opinfo, client_guid, lctx->lease_key); in same_client_has_lease()
523 m_opinfo = opinfo; in same_client_has_lease()
525 if (atomic_read(&opinfo->breaking_cnt)) in same_client_has_lease()
537 lease_read_to_write(opinfo); in same_client_has_lease()
553 lease_none_upgrade(opinfo, lctx->req_state); in same_client_has_lease()
562 static void wait_for_break_ack(struct oplock_info *opinfo) in wait_for_break_ack() argument
566 rc = wait_event_interruptible_timeout(opinfo->oplock_q, in wait_for_break_ack()
567 opinfo->op_state == OPLOCK_STATE_NONE || in wait_for_break_ack()
568 opinfo->op_state == OPLOCK_CLOSING, in wait_for_break_ack()
573 if (opinfo->is_lease) in wait_for_break_ack()
574 opinfo->o_lease->state = SMB2_LEASE_NONE_LE; in wait_for_break_ack()
575 opinfo->level = SMB2_OPLOCK_LEVEL_NONE; in wait_for_break_ack()
576 opinfo->op_state = OPLOCK_STATE_NONE; in wait_for_break_ack()
580 static void wake_up_oplock_break(struct oplock_info *opinfo) in wake_up_oplock_break() argument
582 clear_bit_unlock(0, &opinfo->pending_break); in wake_up_oplock_break()
585 wake_up_bit(&opinfo->pending_break, 0); in wake_up_oplock_break()
588 static int oplock_break_pending(struct oplock_info *opinfo, int req_op_level) in oplock_break_pending() argument
590 while (test_and_set_bit(0, &opinfo->pending_break)) { in oplock_break_pending()
591 wait_on_bit(&opinfo->pending_break, 0, TASK_UNINTERRUPTIBLE); in oplock_break_pending()
594 opinfo->open_trunc = 0; in oplock_break_pending()
596 if (opinfo->op_state == OPLOCK_CLOSING) in oplock_break_pending()
598 else if (opinfo->level <= req_op_level) { in oplock_break_pending()
599 if (opinfo->is_lease == false) in oplock_break_pending()
602 if (opinfo->o_lease->state != in oplock_break_pending()
609 if (opinfo->level <= req_op_level) { in oplock_break_pending()
610 if (opinfo->is_lease == false) { in oplock_break_pending()
611 wake_up_oplock_break(opinfo); in oplock_break_pending()
614 if (opinfo->o_lease->state != in oplock_break_pending()
617 wake_up_oplock_break(opinfo); in oplock_break_pending()
702 static int smb2_oplock_break_noti(struct oplock_info *opinfo) in smb2_oplock_break_noti() argument
704 struct ksmbd_conn *conn = opinfo->conn; in smb2_oplock_break_noti()
718 br_info->level = opinfo->level; in smb2_oplock_break_noti()
719 br_info->fid = opinfo->fid; in smb2_oplock_break_noti()
720 br_info->open_trunc = opinfo->open_trunc; in smb2_oplock_break_noti()
724 work->sess = opinfo->sess; in smb2_oplock_break_noti()
726 if (opinfo->op_state == OPLOCK_ACK_WAIT) { in smb2_oplock_break_noti()
730 wait_for_break_ack(opinfo); in smb2_oplock_break_noti()
733 if (opinfo->level == SMB2_OPLOCK_LEVEL_II) in smb2_oplock_break_noti()
734 opinfo->level = SMB2_OPLOCK_LEVEL_NONE; in smb2_oplock_break_noti()
803 static int smb2_lease_break_noti(struct oplock_info *opinfo) in smb2_lease_break_noti() argument
805 struct ksmbd_conn *conn = opinfo->conn; in smb2_lease_break_noti()
809 struct lease *lease = opinfo->o_lease; in smb2_lease_break_noti()
831 work->sess = opinfo->sess; in smb2_lease_break_noti()
833 if (opinfo->op_state == OPLOCK_ACK_WAIT) { in smb2_lease_break_noti()
834 list_for_each_safe(tmp, t, &opinfo->interim_list) { in smb2_lease_break_noti()
846 wait_for_break_ack(opinfo); in smb2_lease_break_noti()
849 if (opinfo->o_lease->new_state == SMB2_LEASE_NONE_LE) { in smb2_lease_break_noti()
850 opinfo->level = SMB2_OPLOCK_LEVEL_NONE; in smb2_lease_break_noti()
851 opinfo->o_lease->state = SMB2_LEASE_NONE_LE; in smb2_lease_break_noti()
857 static void wait_lease_breaking(struct oplock_info *opinfo) in wait_lease_breaking() argument
859 if (!opinfo->is_lease) in wait_lease_breaking()
862 wake_up_interruptible_all(&opinfo->oplock_brk); in wait_lease_breaking()
863 if (atomic_read(&opinfo->breaking_cnt)) { in wait_lease_breaking()
866 ret = wait_event_interruptible_timeout(opinfo->oplock_brk, in wait_lease_breaking()
867 atomic_read(&opinfo->breaking_cnt) == 0, in wait_lease_breaking()
870 atomic_set(&opinfo->breaking_cnt, 0); in wait_lease_breaking()
949 struct oplock_info *opinfo; in destroy_lease_table() local
963 list_for_each_entry_rcu(opinfo, &lb->lease_list, in destroy_lease_table()
966 lease_del_list(opinfo); in destroy_lease_table()
979 struct oplock_info *opinfo; in find_same_lease_key() local
1003 list_for_each_entry_rcu(opinfo, &lb->lease_list, lease_entry) { in find_same_lease_key()
1004 if (!atomic_inc_not_zero(&opinfo->refcount)) in find_same_lease_key()
1007 if (opinfo->o_fp->f_ci == ci) in find_same_lease_key()
1009 err = compare_guid_key(opinfo, sess->ClientGUID, in find_same_lease_key()
1015 opinfo_put(opinfo); in find_same_lease_key()
1019 opinfo_put(opinfo); in find_same_lease_key()
1044 static int add_lease_global_list(struct oplock_info *opinfo) in add_lease_global_list() argument
1050 if (!memcmp(lb->client_guid, opinfo->conn->ClientGUID, in add_lease_global_list()
1052 opinfo->o_lease->l_lb = lb; in add_lease_global_list()
1053 lease_add_list(opinfo); in add_lease_global_list()
1064 memcpy(lb->client_guid, opinfo->conn->ClientGUID, in add_lease_global_list()
1068 opinfo->o_lease->l_lb = lb; in add_lease_global_list()
1069 lease_add_list(opinfo); in add_lease_global_list()
1074 static void set_oplock_level(struct oplock_info *opinfo, int level, in set_oplock_level() argument
1080 grant_write_oplock(opinfo, level, lctx); in set_oplock_level()
1083 grant_read_oplock(opinfo, lctx); in set_oplock_level()
1086 grant_none_oplock(opinfo, lctx); in set_oplock_level()
1094 struct oplock_info *opinfo; in smb_send_parent_lease_break_noti() local
1105 list_for_each_entry(opinfo, &p_ci->m_op_list, op_entry) { in smb_send_parent_lease_break_noti()
1106 if (opinfo->conn == NULL || !opinfo->is_lease) in smb_send_parent_lease_break_noti()
1109 if (opinfo->o_lease->state != SMB2_OPLOCK_LEVEL_NONE && in smb_send_parent_lease_break_noti()
1111 !compare_guid_key(opinfo, fp->conn->ClientGUID, in smb_send_parent_lease_break_noti()
1113 if (!atomic_inc_not_zero(&opinfo->refcount)) in smb_send_parent_lease_break_noti()
1116 if (ksmbd_conn_releasing(opinfo->conn)) in smb_send_parent_lease_break_noti()
1119 oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE); in smb_send_parent_lease_break_noti()
1120 opinfo_put(opinfo); in smb_send_parent_lease_break_noti()
1130 struct oplock_info *opinfo; in smb_lazy_parent_lease_break_close() local
1134 opinfo = rcu_dereference(fp->f_opinfo); in smb_lazy_parent_lease_break_close()
1137 if (!opinfo || !opinfo->is_lease || opinfo->o_lease->version != 2) in smb_lazy_parent_lease_break_close()
1145 list_for_each_entry(opinfo, &p_ci->m_op_list, op_entry) { in smb_lazy_parent_lease_break_close()
1146 if (opinfo->conn == NULL || !opinfo->is_lease) in smb_lazy_parent_lease_break_close()
1149 if (opinfo->o_lease->state != SMB2_OPLOCK_LEVEL_NONE) { in smb_lazy_parent_lease_break_close()
1150 if (!atomic_inc_not_zero(&opinfo->refcount)) in smb_lazy_parent_lease_break_close()
1153 if (ksmbd_conn_releasing(opinfo->conn)) in smb_lazy_parent_lease_break_close()
1155 oplock_break(opinfo, SMB2_OPLOCK_LEVEL_NONE); in smb_lazy_parent_lease_break_close()
1156 opinfo_put(opinfo); in smb_lazy_parent_lease_break_close()
1182 struct oplock_info *opinfo = NULL, *prev_opinfo = NULL; in smb_grant_oplock() local
1195 opinfo = alloc_opinfo(work, pid, tid); in smb_grant_oplock()
1196 if (!opinfo) in smb_grant_oplock()
1200 err = alloc_lease(opinfo, lctx); in smb_grant_oplock()
1203 opinfo->is_lease = 1; in smb_grant_oplock()
1225 copy_lease(m_opinfo, opinfo); in smb_grant_oplock()
1227 opinfo->o_lease->flags = in smb_grant_oplock()
1284 set_oplock_level(opinfo, req_op_level, lctx); in smb_grant_oplock()
1287 rcu_assign_pointer(fp->f_opinfo, opinfo); in smb_grant_oplock()
1288 opinfo->o_fp = fp; in smb_grant_oplock()
1291 opinfo_add(opinfo); in smb_grant_oplock()
1292 if (opinfo->is_lease) { in smb_grant_oplock()
1293 err = add_lease_global_list(opinfo); in smb_grant_oplock()
1300 free_opinfo(opinfo); in smb_grant_oplock()
1760 struct oplock_info *opinfo = NULL, *ret_op = NULL; in lookup_lease_in_table() local
1776 list_for_each_entry_rcu(opinfo, &lt->lease_list, lease_entry) { in lookup_lease_in_table()
1777 if (!atomic_inc_not_zero(&opinfo->refcount)) in lookup_lease_in_table()
1780 if (!opinfo->op_state || opinfo->op_state == OPLOCK_CLOSING) in lookup_lease_in_table()
1782 if (!(opinfo->o_lease->state & in lookup_lease_in_table()
1786 ret = compare_guid_key(opinfo, conn->ClientGUID, in lookup_lease_in_table()
1790 ret_op = opinfo; in lookup_lease_in_table()
1794 opinfo_put(opinfo); in lookup_lease_in_table()
1810 struct oplock_info *opinfo = opinfo_get(fp); in smb2_check_durable_oplock() local
1813 if (!opinfo) in smb2_check_durable_oplock()
1816 if (opinfo->is_lease == false) { in smb2_check_durable_oplock()
1823 if (opinfo->level != SMB2_OPLOCK_LEVEL_BATCH) { in smb2_check_durable_oplock()
1844 if (memcmp(opinfo->o_lease->lease_key, lctx->lease_key, in smb2_check_durable_oplock()
1852 if (!(opinfo->o_lease->state & SMB2_LEASE_HANDLE_CACHING_LE)) { in smb2_check_durable_oplock()
1858 if (opinfo->o_lease->version != lctx->version) { in smb2_check_durable_oplock()
1868 opinfo_put(opinfo); in smb2_check_durable_oplock()