oplock.h 3.9 KB

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